<?php
/**
 * Created by PhpStorm.
 * User: 73640
 * Date: 2018/11/12
 * Time: 17:28
 */

namespace App\Repository;


use App\BrokerCall;
use App\BrokerMedia;
use App\Service\TeleService;

class BrokerRepository
{
    public function getVideo(BrokerMedia $brokerMedia){
       $brokerCall= BrokerCall::where("mid",$brokerMedia->mid)->first();
       if ($brokerCall&&!$brokerCall->video){
           $tele=new TeleService();
           $file=   $tele->readFile($brokerMedia->readUrl,$brokerMedia->tag,$brokerMedia->mid);
           //储存
           $fileName='video/'.uniqid().'.'.$file['type'];
           $path=\Storage::put($fileName,$file['data']);
           if($path){
               $brokerCall->video=$fileName;
               $brokerCall->save();
               return $fileName;
           }
           return $brokerCall->video;
       }
        return '';
    }
}